package br.com.sysmap.dollymockup.client.common.business;

import br.com.sysmap.crux.core.client.formatter.Formatter;
import br.com.sysmap.crux.core.client.formatter.InvalidFormatException;
import br.com.sysmap.crux.core.client.formatter.annotation.FormatterName;
import br.com.sysmap.dollymockup.client.common.dto.Role;
import br.com.sysmap.dollymockup.client.common.i18n.ClientMessages;

/**
 * Formatter for user roles
 * @author Gesse Dafe
 */
@FormatterName("role")
public class RoleFormatter implements Formatter
{
	/**
	 * @see br.com.sysmap.crux.core.client.formatter.Formatter#format(java.lang.Object)
	 */
	public String format(Object input) throws InvalidFormatException
	{
		if(Role.ADMINISTRATOR.equals(input))
		{
			return ClientMessages.instance().administrator();
		}
		else
		{
			return ClientMessages.instance().restrictedUser();
		}
	}

	/**
	 * @see br.com.sysmap.crux.core.client.formatter.Formatter#unformat(java.lang.String)
	 */
	public Object unformat(String input) throws InvalidFormatException
	{
		if(ClientMessages.instance().administrator().equals(input))
		{
			return Role.ADMINISTRATOR;
		}
		else
		{
			return Role.RESTRICTED_USER;
		}
	}
}